package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbSellerMapper;
import com.dongdongshop.pojo.seller.TbSeller;
import com.dongdongshop.service.seller.SellerService;
import com.dongdongshop.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class SellerServiceImpl implements SellerService {
    @Autowired
    private TbSellerMapper tbSellerMapper;

    @Override
    public TbSeller getSellerByUsername(String username) {
        return tbSellerMapper.getSellerByUsername(username);
    }

    @Override
    public int register(TbSeller tbSeller) {
        String password = tbSeller.getPassword();
        String salt = ShiroUtils.generateSalt(6);
        String md5Password = ShiroUtils.encryptPassword("MD5", password, salt, 3);
        tbSeller.setPassword(md5Password);
        tbSeller.setSalt(salt);
        int i = tbSellerMapper.insertSelective(tbSeller);
        return i;
    }

    @Override
    public List<TbSeller> listSellerAudit() {
        return tbSellerMapper.listSellerAudit();
    }

    @Override
    public TbSeller getSellerAudit(String sellerId) {
        return tbSellerMapper.selectByPrimaryKey(sellerId);
    }

    @Override
    public int updateSellerStatus(String sellerId, String status) {
        TbSeller tbSeller = new TbSeller();
        tbSeller.setSellerId(sellerId);
        tbSeller.setStatus(status);
        return tbSellerMapper.updateByPrimaryKeySelective(tbSeller);
    }
}
